// Copyrights by Kenneth Lee, 2022. All Rights Reserved

#ifndef __VALIF_HPP__
#define __VALIF_HPP__

#include <iostream>
#include <assert.h>

static const int debug_level = 0;

using namespace std;

class ValIf  {
	public:
		enum VAL_STATE { ST_NON, ST_INV, ST_VAL };
		VAL_STATE state;
		ValIf(): state(ST_NON) {}
		void show(ostream & os) {
			switch(state) {
				case ST_NON:
					os << "?";
					break;
				case ST_INV:
					os << "!";
					break;
				default:
					os << "#";
					assert(false);
					break;
			}
		}
		bool state_compare(const ValIf &r) {
			assert(state != ST_NON);
			assert(r.state != ST_NON);

			if (state != ST_VAL || r.state != ST_VAL)
				return false;

			return true;
		}
		bool op_init(const ValIf &l, const ValIf &r) {
			assert(l.state != ST_NON);
			assert(r.state != ST_NON);

			if (l.state == ST_INV || r.state == ST_INV) {
				state = ST_INV;
				return false;
			} else {
				state = ST_VAL;
				return true;
			}
		}
};

#endif
